/*
 * Copyright (C) 2012 Le Tuan Anh <anh.takaji@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package interceptors;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
import ezcms.dto.User;
import java.util.Map;
import util.ApplicationConstants;
import util.RoleUtil;

/**
 *
 * @author Le Tuan Anh <anh.takaji@gmail.com>
 */
public class ReviewerInterceptor implements Interceptor {

    @Override
    public void destroy() {
    }

    @Override
    public void init() {
    }

    @Override
    public String intercept(ActionInvocation ai) throws Exception {
        Map session = ai.getInvocationContext().getSession();
        User user = (User) session.get(ApplicationConstants.SESSION_USER);
        if (!RoleUtil.hasRole(user, RoleUtil.ROLE_REVIEWER)) {
            return Action.LOGIN;
        } else {
//            Action action = (Action) ai.getAction();
            return ai.invoke();
        }
    }
}
